package springcloudJ.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import springcloudJ.pojo.User;

@Repository
public class SpringCloudDao {
	@Autowired
	private JdbcTemplate jdbcTemplate;
	public List<User> queryUser(){
		String sql = "select  f_username as name,f_gender as gender from cms_user";
		return jdbcTemplate.query(sql, (rs,rowNum) -> {
			User user = new User();
			user.setName(rs.getString("name"));
			user.setGender(rs.getString("gender"));
			return user;
			
		});
		
		/*return jdbcTemplate.query(sql, new RowMapper<User>(){

			@Override
			public User mapRow(ResultSet rs, int rowNum) throws SQLException {
				User user = new User();
				user.setName(rs.getString("name"));
				user.setGender(rs.getString("gender"));
				return user;
			}
			
		});*/
		
	}
	

}
